
#ifndef _IFRUSTUM_H_
#define _IFRUSTUM_H_

#include <BBox>
#include <BSpace>
#include <BPlane>

namespace BWE
{
	template<class T>
	class IFrustumX
	{
	public:
		inline bool clip(const BVectorX<T>& v) const
		{
			if (plane_near.clip(v))
				return true;
			if (plane_far.clip(v))
				return true;
			if (plane_left.clip(v))
				return true;
			if (plane_right.clip(v))
				return true;
			if (plane_top.clip(v))
				return true;
			if (plane_bottom.clip(v))
				return true;
			return false;
		}
		inline bool clip(const BBoxX<T>& box) const
		{
			if (plane_near.clip(box))
				return true;
			if (plane_far.clip(box))
				return true;
			if (plane_left.clip(box))
				return true;
			if (plane_right.clip(box))
				return true;
			if (plane_top.clip(box))
				return true;
			if (plane_bottom.clip(box))
				return true;
			return false;
		}

		inline BSpace space() const
		{
			BSpace s(near_v0);
			s.expand(near_v1);
			s.expand(near_v2);
			s.expand(near_v3);
			s.expand(far_v0);
			s.expand(far_v1);
			s.expand(far_v2);
			s.expand(far_v3);
			return s;
		}

		BPlane				plane_near;
		BPlane				plane_far;
		BPlane				plane_left;
		BPlane				plane_right;
		BPlane				plane_top;
		BPlane				plane_bottom;
		BVector				near_v0;
		BVector				near_v1;
		BVector				near_v2;
		BVector				near_v3;
		BVector				far_v0;
		BVector				far_v1;
		BVector				far_v2;
		BVector				far_v3;
	};

	typedef IFrustumX<BReal>		IFrustum;
}

#endif